package com.loong.musicdemo.ui.find.activity.ui.detail;

import android.content.Context;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.loong.musicdemo.model.Singer;
import com.loong.musicdemo.ui.find.activity.ui.detail.fragment.SingerAboutFragment;
import com.loong.musicdemo.ui.find.activity.ui.detail.fragment.SingerAlbumFragment;
import com.loong.musicdemo.ui.find.activity.ui.detail.fragment.SingerMvFragment;
import com.loong.musicdemo.ui.find.activity.ui.detail.fragment.SingerSongFragment;

/**
 * A [FragmentPagerAdapter] that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {

    private static final String[] titles = new String[]{"歌曲","专辑","视频","关于TA"};
    private final Context mContext;
    private Singer singer;

    public SectionsPagerAdapter(Context context, FragmentManager fm, Singer singer) {
        super(fm);
        this.mContext = context;
        this.singer = singer;
    }

    @Override
    public Fragment getItem(int position) {
        switch (position){
            case 0 :
                return SingerSongFragment.newInstance(singer.getId());
            case 1:
                return SingerAlbumFragment.newInstance(singer);
            case 2:
                return SingerMvFragment.newInstance(singer.getId());
            default:
                return SingerAboutFragment.newInstance(singer.getId());
        }
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    @Override
    public int getCount() {
        return titles.length;
    }
}